package com.fjp.heartguard.app.weight.title;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.fjp.heartguard.R;
import com.fjp.heartguard.app.data.bean.GroupQuestionType;

import java.util.HashMap;
import java.util.Map;

public class TypeTitleLayout extends LinearLayout {
    private Map<GroupQuestionType, TypeTitle> types = new HashMap<>();
    private TextView titleTv;
    private ImageView iconIv;
    private View bottomLine;

    public TypeTitleLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initType();
        initView();
    }

    public TypeTitleLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initType();
        initView();
    }

    private void initType() {
        types.put(GroupQuestionType.COGNITION_A, new TypeTitle("我是标题1asdfasdfasdfasdfasdfasdfasdfasfdasdfasdfasdfadsf", R.drawable.sb_bar, R.color.purple_200));
        types.put(GroupQuestionType.COGNITION_B, new TypeTitle("我是标题2", R.drawable.ic_launcher_background, R.color.teal_200));
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.type_title_layout, this);
        titleTv = findViewById(R.id.titleTv);
        iconIv = findViewById(R.id.iconIv);
        bottomLine = findViewById(R.id.bottomLine);
    }

    public void setViewByType(GroupQuestionType type) {
        TypeTitle typeTitle = types.get(type);
        assert typeTitle != null;
        titleTv.setText(typeTitle.getTitle());
        iconIv.setBackgroundResource(typeTitle.getImageRes());
        bottomLine.setBackgroundResource(typeTitle.getBottomLineColorRes());

    }

}
